<?php

  //connect to database
  @connectToDb($dbServer, $dbAll, $dbAllPW, $dbName);

  function checkMailingList($title, $surname, $given_name, $address, $pcode)
  {
	
	$sql = "SELECT * FROM mailing_list WHERE title = '" . $title . "' AND surname = '" . $surname . "' AND given_name = '" . $given_name . "' AND address = '" . $address . "' AND pcode = " . $pcode;

    $sql_result = @mysql_query($sql);

    $sql_num = @mysql_numrows($sql_result);

    if($sql_num == 0)
    {
      return true;
    }
    else
    {
      return false;
    }
  }

  function insertToMailingList($title, $surname, $given_name, $address, $pcode)
  {

	$result = mysql_query("SELECT count(*) FROM mailing_list")or die ('Error: '.mysql_error ());
    $row = mysql_fetch_row($result)or die ('Error: '.mysql_error ());
    $id = $row[0] + 1;

    if(mysql_query("INSERT INTO mailing_list VALUES(" . $id . ", '" . $title . "', '" . $surname . "', '" . $given_name . "', '" . $address . "', " . $pcode . ")"))
	{
      return true;
	}
    else
    {
      return false;
    }

	mysql_close();
  }

?>